package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    
    final public class UserAPI extends RestAPI
    {
        // those in comment are not implemented yet
        public static const USER_GET_EVENTS:String               = "user.getEvents";
        public static const USER_GET_FRIENDS:String              = "user.getFriends";
        public static const USER_GET_INFO:String                 = "user.getInfo";
        public static const USER_GET_LOVED_TRACKS:String         = "user.getLovedTracks";
        public static const USER_GET_NEIGHBOURS:String           = "user.getNeighbours";
        public static const USER_GET_PAST_EVENTS:String          = "user.getPastEvents";
        public static const USER_GET_PLAYLISTS:String            = "user.getPlaylists";
        public static const USER_GET_RECENT_TRACKS:String        = "user.getRecentTracks";
        public static const USER_GET_RECOMMENDED_ARTISTS:String  = "user.getRecommendedArtists";
        public static const USER_GET_RECOMMENDED_EVENTS:String   = "user.getRecommendedEvents";
        public static const USER_GET_SHOUTS:String               = "user.getShouts";
        public static const USER_GET_TOP_ALBUMS:String           = "user.getTopAlbums";
        public static const USER_GET_TOP_ARTISTS:String          = "user.getTopArtists"; 
        public static const USER_GET_TOP_TAGS:String            = "user.getTopTags";
        public static const USER_GET_TOP_TRACKS:String           = "user.getTopTracks";
        public static const USER_GET_WEEKLY_ALBUM_CHART:String   = "user.getWeeklyAlbumChart";
        public static const USER_GET_WEEKLY_ARTIST_CHART:String  = "user.getWeeklyArtistChart";
        public static const USER_GET_WEEKLY_CHART_LIST:String    = "user.getWeeklyChartList";
        public static const USER_GET_WEEKLY_TRACK_CHART:String   = "user.getWeeklyTrackChart";
        public static const USER_SHOUT:String                    = "user.shout";
        
        public function UserAPI(agent:Agent)
        {
            super(agent);
        }
        
        /* ********************************************************************/
        

        /** user.getEvents */
        public function getEvents(onComplete:Function, 
                                   onError:Function,
                                   user:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_EVENTS;
            urlVars["user"] = user;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getFriends */
        public function getFriends(onComplete:Function, 
                                   onError:Function,
                                   user:String,
                                   recenttracks:Boolean=false,
                                   page:int=-1,
                                   limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_FRIENDS;
            urlVars["user"] = user;
            urlVars["recenttracks"] = recenttracks;
            if (page>0) urlVars["page"] = page;
            if (limit>0) urlVars["limit"] = limit;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getInfo */
        public function getInfo(onComplete:Function, 
                                   onError:Function):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_INFO;
            requestAPI(URLRequestMethod.GET, urlVars, true, onComplete, onError);        
        }
        

        /** user.getLovedTracks */
        public function getLovedTracks(onComplete:Function, 
                                   onError:Function,
                                   user:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_LOVED_TRACKS;
            urlVars["user"] = user;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getNeighbours */
        public function getNeighbours(onComplete:Function, 
                                   onError:Function,
                                   user:String,
                                   limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_NEIGHBOURS;
            urlVars["user"] = user;
            if (limit>0) urlVars["limit"] = limit;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getPastEvents */
        public function getPastEvents(onComplete:Function, 
                                   onError:Function,
                                   user:String,
                                   page:int=-1,
                                   limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_PAST_EVENTS;
            urlVars["user"] = user;
            if (page>0) urlVars["page"] = page;
            if (limit>0) urlVars["limit"] = limit;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getPlaylists */
        public function getPlaylists(onComplete:Function, 
                                   onError:Function,
                                   user:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_PLAYLISTS;
            urlVars["user"] = user;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        

        /** user.getRecentTracks */
        public function getRecentTracks(onComplete:Function, 
                                   onError:Function,
                                   user:String,
                                   limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_RECENT_TRACKS;
            urlVars["user"] = user;
            if (limit>0) urlVars["limit"] = limit;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getRecommendedArtists */
        public function getRecommendedArtists(onComplete:Function, 
                                   onError:Function):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_RECOMMENDED_ARTISTS;
            requestAPI(URLRequestMethod.GET, urlVars, true, onComplete, onError);        
        }
        

        /** user.getRecommendedEvents */
        public function getRecommendedEvents(onComplete:Function, 
                                             onError:Function,
                                             page:int=-1,
                                             limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_RECOMMENDED_EVENTS;
            if (page>0) urlVars["page"] = page;
            if (limit>0) urlVars["limit"] = limit;
            requestAPI(URLRequestMethod.GET, urlVars, true, onComplete, onError);        
        }
        

        /** user.getShouts */
        public function getShouts(onComplete:Function, 
                                   onError:Function,
                                   user:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_SHOUTS;
            urlVars["user"] = user;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getTopAlbums */
        public function getTopAlbums(onComplete:Function, 
                                   onError:Function,
                                   user:String,
                                   period:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_TOP_ALBUMS;
            urlVars["user"] = user;
            if (period!=null) urlVars["period"] = period;             
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        

        /** user.getTopArtists */
        public function getTopArtists(onComplete:Function,
                                      onError:Function,
                                      user:String, 
                                      period:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_TOP_ARTISTS;
            urlVars["user"] = user;
            if (period!=null) urlVars["period"] = period;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        
        /** user.getTopTags */
        public function getTopTags(onComplete:Function,
                                      onError:Function,
                                      user:String, 
                                      limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_TOP_TAGS;
            urlVars["user"] = user;
            if (limit>0) urlVars["limit"] = limit;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getTopTracks */
        public function getTopTracks(onComplete:Function,
                                      onError:Function,
                                      user:String, 
                                      period:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_TOP_TRACKS;
            urlVars["user"] = user;
            if (period!=null) urlVars["period"] = period;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        
        /** user.getWeeklyAlbumChart */
        public function getWeeklyAlbumChart(onComplete:Function,
                                      onError:Function,
                                      user:String, 
                                      from:String=null,
                                      to_:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_WEEKLY_ALBUM_CHART;
            urlVars["user"] = user;
            if (from!=null) urlVars["from"] = from;
            if (to_!=null) urlVars["to"] = to_;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        
        /** user.getWeeklyArtistChart */
        public function getWeeklyArtistChart(onComplete:Function,
                                      onError:Function,
                                      user:String, 
                                      from:String=null,
                                      to_:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_WEEKLY_ARTIST_CHART;
            urlVars["user"] = user;
            if (from!=null) urlVars["from"] = from;
            if (to_!=null) urlVars["to"] = to_;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        
        
        /** user.getWeeklyChartList */
        public function getWeeklyChartList(onComplete:Function, 
                                   onError:Function,
                                   user:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_WEEKLY_CHART_LIST;
            urlVars["user"] = user;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.getWeeklyTrackChart */
        public function getWeeklyTrackChart(onComplete:Function,
                                      onError:Function,
                                      user:String, 
                                      from:String=null,
                                      to_:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_GET_WEEKLY_TRACK_CHART;
            urlVars["user"] = user;
            if (from!=null) urlVars["from"] = from;
            if (to_!=null) urlVars["to"] = to_;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** user.shout */
        public function shout(onComplete:Function,
                                      onError:Function,
                                      user:String, 
                                      message:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = UserAPI.USER_SHOUT;            
            urlVars["user"] = user;            
            urlVars["message"] = message;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }
        
  
    }
}